<template>
    <div>
        <el-row>
        <b>房产类型：</b>
        <el-radio-group v-model="radio1" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">住宅</el-radio-button>
        <el-radio-button label="2">车位</el-radio-button>
        <el-radio-button label="3">仓房</el-radio-button>
        <el-radio-button label="4">商户</el-radio-button>
        <el-radio-button label="5">车库</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>入住状态：</b>
        <el-radio-group v-model="radio2" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">已入住</el-radio-button>
        <el-radio-button label="2">未入住</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>门牌/编号：</b>
        <el-input palceholder="请输入楼号/弄号" v-model="number" style="width
        :250px;"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="initTable">查询</el-button>
    </el-row>

    <el-row>
        <!-- <el-button type="danger" plain icon="el-icon-delete" @click="deleteIds">删除</el-button> -->
        <el-button type="info" plain icon="el-icon-upload2" @click="exportproperty">导出</el-button>
        <el-button type="info" plain icon="el-icon-download" @click="downloadmodel">下载模板</el-button>
        <el-upload action="http://localhost:8099/file/importProperty" 
        style="display: inline-block;margin-left: 10px;"
        :show-file-list="false"
        accept="xlsx"
        :on-success="success">
            <el-button type="warning" plain icon="el-icon-download">导入</el-button>
        </el-upload>
    </el-row>

    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="detail"
        label="详细">
      </el-table-column>
      <el-table-column
        prop="type"
        label="房产类型">
        <template slot-scope="scope">
            <el-tag :type="scope.row.tagColor">{{ scope.row.propertyType }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="导入时间">
      </el-table-column>
      <el-table-column
        prop="checkInTime"
        label="入住时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-search" @click="ToPropertyInfo(scope.row.id)" >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
    </div>
</template>

<script>
export default {
    name:'property',
    data(){
        return{
            radio1: "0",
            radio2: "0",
            tableData: [],
            currentPage:1,
            pageSize:10,
            total:0,
            number:''
        }
    },
    created(){
        this.initAuthority()
    },
    methods:{
        initAuthority(){
        this.$request.get("/role/authority",{
          params:{
            id: JSON.parse(localStorage.getItem("admin")).id,
            index: 8
          }
        })
        .then(res =>{
          this.Authority = res.data
          if(res.data == '1'){
            this.initTable()
          }else{
            this.$message.error("你没有权限访问此功能")
            // this.$router.push("/")
          }
        })
        .catch(err =>{
          console.log(err)
        })

      },
        success(){
            this.$message.success("数据导入成功")
            this.initTable()
        },
        exportproperty(){
            window.open("http://localhost:8099/file/propertyExport")
        },
        downloadmodel(){
            window.open("http://localhost:8099/file/property/model")
        },
        ToPropertyInfo(id){
            this.$router.push({
            path: 'propertyInfo',
            query:{
                ID:id
            }
           })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
            this.initTable()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.initTable()
        },
        initTable(){
            this.$request.get("/property/page",{
                params:{
                    page: this.currentPage,
                    size: this.pageSize,
                    type:this.radio1,
                    checkIn:this.radio2,
                    number:this.number
                }
            }).then(res => {
                this.tableData = res.data.records
                this.total = res.data.total
            }).catch(err =>{
                console.log(err)
            })
        },
    }
}
</script>

<style scoped>
    .el-row{
        margin-bottom: 20px;
    }
</style>